import java.util.*;

public class Main {

    //
    public static void main1(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n + 1];
        for(int i = 1; i <= n; i++){
            arr[i] = in.nextInt();
        }

        int[] f = new int[n + 1];
        int[] g = new int[n + 1];
        f[1] = arr[1];
        for(int i = 2; i <= n; i++){
            int x = arr[i];
            f[i] = Math.max(f[i - 1], x);
            if(x >= f[i - 1]){
                g[i] = f[i - 1];
            }else if(x >= g[i - 1]){
                g[i] = x;
            }else{
                g[i] = g[i - 1];
            }
        }

        int q = in.nextInt();
        while(q-- != 0){
            int t = in.nextInt();
            System.out.println(g[t]);
        }
    }

    //
    public static int n;
    public static int[][] arr;

    public static void setRow(){
        for(int i = 0; i < n / 2; i++){
            for(int j = 0; j < n; j++){
                int t = arr[i][j];
                arr[i][j] = arr[n - i - 1][j];
                arr[n - i - 1][j] = t;
            }
        }
    }
    public static void setCol(){
        for(int j = 0; j < n / 2; j++){
            for(int i = 0; i < n; i++){
                int t = arr[i][j];
                arr[i][j] = arr[i][n - j - 1];
                arr[i][n - j - 1] = t;
            }
        }
    }

    public static void main2(String[] args){
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        arr = new int[n][n];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                arr[i][j] = in.nextInt();
            }
        }
        int q = in.nextInt();
        int row = 0, col = 0;
        while(q-- != 0){
            int t = in.nextInt();
            if(t == 1){
                row++;
                col++;
            }else{
                col++;
            }
        }

        row %= 2;
        col %= 2;

        if(row != 0) { setRow();}
        if(col != 0) { setCol();}

        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }

    //
    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), k = in.nextInt();
        long[] arr = new long[n + 1];
        for(int i = 1; i <= n; i++){
            arr[i] = in.nextLong();
        }

        long[][] dp = new long[n + 1][k];
        for(int i = 0; i <= n; i++){
            for(int j = 0; j < k; j++){
                dp[i][j] = (long) -1e16;
            }
        }
        dp[0][0] = 0;

        for(int i = 1; i <= n; i++){
            for(int j = 0; j < k; j++){
                dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][(int)((j - arr[i] % (long) k + (long) k) % (long) k)] + arr[i]);
            }
        }

        if(dp[n][0] > 0){
            System.out.println(dp[n][0]);
        }else{
            System.out.println(-1);
        }
    }

    //
    public static void main4(String[] args) {
        ListNode head = new ListNode(1);
        ListNode tmp = head;
        head.next = new ListNode(2);
        head = head.next;
        head.next = new ListNode(3);
        head = head.next;
        head.next = new ListNode(4);
        head = head.next;
        head.next = new ListNode(5);

        ListNode ret = reverseList(tmp);
    }

    public static ListNode reverseList(ListNode head) {
        ListNode cur = head;
        ListNode pre = null;
        while(cur != null){
            ListNode curNext = cur.next;
            cur.next = pre;
            pre = cur;
            cur = curNext;
        }
        return pre;
    }

    //
    public static void main5(String[] args){
        Scanner in = new Scanner(System.in);

        int[] hash = new int[26];
        char ret = 0;
        int maxCount = 0;

        while(in.hasNext()){
            char[] s = in.next().toCharArray();
            for(char ch : s){
                if(++hash[ch - 'a'] > maxCount){
                    ret = ch;
                    maxCount = hash[ch - 'a'];
                }
            }
        }
        System.out.println(ret);
    }

    //
    public static void main6(String[] args) {
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            //1.统计所有字符的频次
            char[] s = in.next().toCharArray();
            int[] hash = new int[300];
            for(char ch : s){
                hash[ch]++;
            }

            //2.把所有的频次放入到堆里面
            PriorityQueue<Integer> heap = new PriorityQueue<>();
            for(int i = 0; i < 300; i++){
                if(hash[i] != 0){
                    heap.offer(hash[i]);
                }
            }

            //3.哈夫曼编码
            int ret = 0;
            while(heap.size() > 1){
                int t1 = heap.poll();
                int t2 = heap.poll();
                ret += t1 + t2;
                heap.offer(t1 + t2);
            }
            System.out.println(ret);
        }
    }

    //
    public static void main7(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int[] dp = new int[n + 1];
        for(int i = 0; i <= n; i++){
            dp[i] = 0x3f3f3f3f;
        }
        dp[0] = 0;

        for(int i = 1; i * i <= n; i++){
            for(int j = i * i; j <= n; j++){
                dp[j] = Math.min(dp[j], dp[j - i * i] + 1);
            }
        }
        System.out.println(dp[n]);
    }
}
